const { ErrStatusMap } = require('./error')
// 
const respHttp = (ctx, respCode, data) => {
  const resp = {
    code: 200,
    data: '',
    message: 'success'
  }
  if (respCode !== 200) {
    resp.code = respCode
    resp.message = ErrStatusMap[respCode]
  } else {
    resp.data = data
  }
  ctx.body = resp
}
// 请求成功
const RespSuccess = ctx => {
  respHttp(ctx, 200)
}
// 请求失败
const RespError = (ctx, respCode) => {
  respHttp(ctx, respCode)
}
// 请求成功且返回数据
const RespData = (ctx, data) => {
  respHttp(ctx, 200, data)
}
// 请求成功且返回列表
const RespRows = (ctx, data) => {
  respHttp(ctx, 200, data)
}
module.exports = {
  RespSuccess,
  RespError,
  RespData,
  RespRows
}